from osgeo import ogr
import os

shpfile = os.path.join(os.getcwd(),"include","dataset","shp.shp")

if os.path.exists(shpfile):
    drv: ogr.Driver = ogr.GetDriverByName("Esri shapefile")
    dataSource:ogr.DataSource = drv.Open(shpfile, 1)
    layer: ogr.Layer = dataSource.GetLayer(0)
    layerDefn:ogr.FeatureDefn = layer.GetLayerDefn()
    field_list = []
    for index in range(layerDefn.GetFieldCount()):
        field_defn:ogr.FieldDefn = layerDefn.GetFieldDefn(index)
        field_name = field_defn.GetName()
        field_type = field_defn.GetTypeName()
        field_width = field_defn.GetWidth()
        field_list.append({'field_name':field_name, 'field_type':field_type, 'field_width': field_width})
    
    feature_update:ogr.Feature = layer.GetFeature(69)
    for element in field_list:
        filed_index = element["field_name"]
        value = feature_update.GetField(filed_index)
        if value == 'A69':
            feature_update.SetField2(filed_index, "python")
            layer.SetFeature(feature_update)
            feature_update = None
    dataSource.Destroy()
else:
    print("数据不存在！")